package com.itetchologyandenglish.home.controller.Page;

import com.itetchologyandenglish.home.enetity.News;
import com.itetchologyandenglish.home.enetity.Result;
import com.itetchologyandenglish.home.service.NewsService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

@Controller
public class NewaPageController {
    @Resource
    NewsService newsService;
    @RequestMapping("/page/news")
    public ModelAndView news(ModelAndView model){
        model.setViewName("news");
        return model;
    }
    @RequestMapping("/news/newsDetail")
    public ModelAndView newsDetail(ModelAndView model,Integer id){
        model.getModel().put("id",id);
        model.setViewName("newsDetail");
        return model;
    }
    @RequestMapping(value="/news/addNews")
    public ModelAndView upNewsById(@RequestParam(value="id",required = false) Integer id,ModelAndView model){
        System.out.println(id);
        News news=newsService.findNewsById(id);
        model.getModel().put("news",news);
        model.setViewName("addNews");
        return model;
    }
    @RequestMapping("/page/assistant")
    public ModelAndView assistant(ModelAndView model){
        model.setViewName("assistant");
        return model;
    }
    @RequestMapping(value="/news/newsPreview")
    public ModelAndView newsPreview(ModelAndView model){
//        model.getModel().put("newspre",)
        return new ModelAndView("newsPreview");
    }

}
